package com.lry.web.video.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lry.web.video.entity.Video;
import com.lry.web.video.entity.VideoUpdate;
import com.lry.web.video.mapper.VideoUpdateMapper;
import com.lry.web.video.service.VideoUpdateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class VideoUpdateServiceImpl implements VideoUpdateService {
    @Autowired
    VideoUpdateMapper videoUpdateMapper;


    public int setVideoUpdate(VideoUpdate videoUpdate) {
        return videoUpdateMapper.insert(videoUpdate);
    }


    public List<VideoUpdate> getVideoUpdates() {
        return videoUpdateMapper.selectList(null);
    }


    public int setVideoUpdateUp(VideoUpdate videoUpdate) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("video_id",videoUpdate.getVideoId());
        return videoUpdateMapper.update(videoUpdate,wrapper);
    }


    public int deleteByVideoId(String videoId) {
        List<String> listVId = Arrays.asList(videoId.split(","));
        int i = 0;
        for(String id:listVId){
            i = videoUpdateMapper.deleteByVideoId(id);
        }
        return i;
    }


    public int deleteByVVId(String vVId) {
        return videoUpdateMapper.deleteByVVId(vVId);
    }

    @Override
    public Map<String,VideoUpdate> selectByVideo(List<Video> videos) {
        Map<String,VideoUpdate> map = new HashMap<>();
        for(Video v: videos){
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("video_id",v.getVideoId());
           map.put(v.getVideoId(),videoUpdateMapper.selectOne(wrapper));
        }
        return map;

        }

    @Override
    public int updateDeleted(String videoId) {
        return videoUpdateMapper.updateDeleted(videoId);
    }

    @Override
    public int deleteByVId(String id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("video_id",id);
        return videoUpdateMapper.delete(wrapper);
    }

}
